﻿using Codeplus.Library.Recaptcha;
using Codeplus.Library.Data;
using System;

namespace Codeplus.Library.Models
{
    public class ContactUsModel
    {
        public RecaptchaModel Recaptcha { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmailAddress { get; set; }
        public string PhoneNumber { get; set; }
        public string ServiceCode { get; set; }
        public string City { get; set; }
        public string CountryCode { get; set; }
        public string CountryName { get; set; }
        public float Longitude { get; set; }
        public float Latitude { get; set; }
        public string IPAddress { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public void NewEnquiry()
        {
            var context = AppDataContext.GetContext();
            using (context)
            {
                context.NewEnquiry(this.FirstName, this.LastName, this.EmailAddress, this.PhoneNumber, this.ServiceCode,
                                   this.CountryCode, this.CountryName, this.City, this.Longitude, this.Latitude,
                                   this.IPAddress);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return
                string.Format(
                    "Name: [{1} {2}]{0}Email: [{3}]{0}Phone:[{4}]{0}Service: [{5}]{0}City: [{6}]{0}Country: [{7}]{0}IP Address: [{8}]",
                    "<br/>", FirstName, LastName, EmailAddress, PhoneNumber, ServiceCode, City, CountryName, IPAddress);
        }
    }
}